package cn.achao.csr.api.factory;

import cn.achao.csr.api.SysUserApi;
import cn.achao.csr.api.model.dto.AuthDTO;
import cn.achao.csr.api.model.dto.RegisterDTO;
import cn.achao.csr.api.model.entity.LoginUser;
import cn.achao.csr.api.model.entity.SysUser;
import cn.achao.csr.base.constant.enums.ThirdAuthEnum;
import cn.achao.csr.base.resp.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Author: achao
 **/
@Slf4j
@Component
public class SysUserFallbackFactory implements FallbackFactory<SysUserApi> {

    @Override
    public SysUserApi create(Throwable throwable) {
        return new SysUserApi() {
            @Override
            public R<LoginUser> register(RegisterDTO req) {
                log.error("注册用户失败,服务不可用:{}", throwable.getMessage());
                return R.fail("注册用户失败");
            }

            @Override
            public R<LoginUser> info(String userAccount, String source) {
                log.error("获取用户失败:{}", throwable.getMessage());
                return R.fail("获取用户失败");
            }

            @Override
            public R<LoginUser> infoByZfbOpenId(String openId, String source) {
                log.error("根据支付宝openId【{}】获取用户失败:{}", openId, throwable.getMessage());
                return R.fail("获取用户失败");
            }


            @Override
            public R<LoginUser> updateZfbOpenId(AuthDTO req, String source) {
                log.error("openId【{}】 userAccount【{}】 支付宝用户授权失败{}", req.getOpenId(), req.getUserAccount(), throwable.getMessage());
                return R.fail("支付宝用户授权失败");
            }

            @Override
            public R<Boolean> isExistOpenId(String openId, ThirdAuthEnum thirdAuthEnum, String source) {
                log.error("根据openId【{}】判断用户是否存在失败:{}", openId, throwable.getMessage());
                return R.fail();
            }

            @Override
            public R<Map<Long, SysUser>> getUserListByIds(List<Long> userIds, String source) {
                log.error("查询用户列表失败:{}", throwable.getMessage());
                return R.fail();
            }
        };
    }
}
